import { request } from '@umijs/max'

export interface UserItem {
  id: number
  userName: string
  userCode: string
  email: string
  pic: string
}

export interface CreatorItem {
  creatorUserCode: string
  domain: string
  pic: string
  userName: string
  address: string
  userCode: string
}

interface ApiResponse<T> {
  code: number
  msg: string
  data: T
  success: boolean
}


/** 查看子账号列表 */
export async function userList(data: any) {
  return request<ApiResponse<any>>('/api/ofm/ofm-user/v1/child/list', {
    method: 'POST',
    data,
  })
}

/** 查看账号详情 */
export async function userDetail(data: {
  id: number // 用户id
}) {
  return request<ApiResponse<any>>('/api/ofm/ofm-user/v1/detail', {
    method: 'POST',
    data
  })
}

/** 获取关联创作者列表 */
export async function relCreatorList(data?: any) {
  return request<ApiResponse<any>>('/api/ofm/ofm-user-creator-rel/v1/rel-creator/list', {
    method: 'POST',
    data
  })
}


/** 机构创建子账号 */
export async function userCreate(data: {
  creatorUserCodes: string[], // 	创作者UserCode
  email: string, // 邮箱
  ofmRoleIds: number[], // 角色ID
  password: string, // 密码
  userName: string // 用户名
}) {
  return request<ApiResponse<any>>('/api/ofm/ofm-user/v1/child/create', {
    method: 'POST',
    data
  })
}

/** 机构修改子账号 */
export async function userUpdate(data: {
  creatorUserCodes: string[], // 	创作者UserCode
  email: string, // 邮箱
  ofmRoleIds: number[], // 角色ID
  userName: string // 用户名
  id: number // 用户id
}) {
  return request<ApiResponse<any>>('/api/ofm/ofm-user/v1/child/update', {
    method: 'POST',
    data
  })
}


/** 删除账号 */
export async function userDelete(data: {
  id: number // 用户id
}) {
  return request<ApiResponse<any>>('/api/ofm/ofm-user/v1/child/delete', {
    method: 'POST',
    data
  })
}

/** 修改密码 */
export async function updatePassword(data: {
  ofmUserId: number // 用户id
  password: string // 密码
}) {
  return request<ApiResponse<any>>('/api/ofm/ofm-user/v1/password/update', {
    method: 'POST',
    data
  })
}

/** 媒体域名配置接口 */
export interface MediaDomainConfig {
  id: number
  firstDomain: string
  secondDomain: string
  thirdDomain: string
}

/** 查询媒体域名配置列表 */
export async function queryMediaDomainConfigList() {
  return request<ApiResponse<MediaDomainConfig[]>>('/api/user/common/queryMediaDomainConfigList', {
    method: 'GET'
  })
}
